from PySide2 import QtWidgets, QtGui, QtCore
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtGui import *
import sys


class Demo(QWidget):
    def __init__(self, parent=None):
        super(Demo, self).__init__(parent)
        self.setWindowTitle("使用QPainter绘制图像")
        self.resize(300, 120)

    def paintEvent(self, event):
        painter = QPainter(self)                           # 创建绘图对象
        painter.setPen(Qt.red)                             # 设置画笔
        painter.drawEllipse(80, 10, 50, 30)                # 绘制一个椭圆
        painter.drawRect(180, 10, 50, 30)                  # 绘制一个矩形
        painter.drawLine(80, 70, 200, 70)                  # 绘制直线
        painter.drawText(90, 100, '敢想敢为，注重细节')       # 绘制文本


if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec_())

